"""Generic representation of colour in dingo-vis.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""

import wx
from OGL import wxThreadSwitch

__author__ = 'John Perks'

class DingoColour(object):
    """API: The class of Colours of Avatars and Arcs.
    
    This is the base class that describes the colouring used within
    the L{Dingo.OGL.SensorGraph}.  This class contains methods for
    getting and setting the colour attributes of a node, and details
    of predefined colour settings to used within simulations
    """
    def __init__(self, colour):
        """Initialise a colour object.
        Creates a new colour object,  Returns a error if a invalid colour is specified
        
        @param colour: The colour to create"""
        object.__init__(self)
        if not isinstance(colour, wx.Color):
            raise TypeError('Not a wx.Color: ' + `colour`);
        self._colour = colour

    def _getColour(self):
        """Return the colour value of the object"""
        return self._colour
    _getColor = _getColour

    @wxThreadSwitch
    def GetRGBCombined(self):
        """API: returns the RGB value packed in a 3-byte integer"""
        return self._colour.GetRGB()

    @wxThreadSwitch
    def GetRGB(self):
        """API: returns a triple of (red, green, blue) intensities"""
        return self.GetRed(), self.GetGreen(), self.GetBlue()

    @wxThreadSwitch
    def GetRed(self):
        """API: Returns the red intensity"""
        return self._colour.Red()

    @wxThreadSwitch
    def GetGreen(self):
        """API: Returns the green intensity"""
        return self._colour.Green()

    @wxThreadSwitch
    def GetBlue(self):
        """API: Returns the blue intensity"""
        return self._colour.Blue()

    @wxThreadSwitch
    def GetName(self):
        """Returns the name of the Colour, if it has one,
        otherwise the empty string"""
        return wx.TheColourDatabase.FindName(self._colour)

    @wxThreadSwitch
    def __cmp__(self, other):

        """API: Used for defining ordering and equality semantics for Colours

        Compares the colour object to another using the
        L{Dingo.OGL.GetRGBCombined} value of each as comparator.
        
        @param other: The colour we wish to compare
        """
        if isinstance(other, DingoColour):
            return cmp(self.GetRGBCombined(), other.GetRGBCombined())
        return NotImplemented

    @wxThreadSwitch
    def __hash__(self):
        """API: Hashing consistent with __cmp__"""
        return self.GetRGBCombined()

    @wxThreadSwitch
    @staticmethod
    def FromName(name):
        """API: Creates a new Colour with given name, or raises ValueError
        The colour to be created should be a WX colour object
        @param name:  The WX.colour name of the colour to create"""
        c = wx.NamedColour(name)
        if c:
            return DingoColour(c)
        else:
            raise ValueError('Invalid colour name: ' + name)

    @wxThreadSwitch
    @staticmethod
    def ExistsNamed(name):
        """API: Returns whether or not exists Colour with given name
        
        @param name: The name we wish to check exists"""
        return bool(wx.TheColourDatabase.FindColour(name))

    @wxThreadSwitch
    @staticmethod
    def FromRGBCombined(rgb):
        """API: Unpacks (red, green, blue) from 3-byte int to make Colour"""
        return DingoColour(wx.ColorRGB(rgb))

    @wxThreadSwitch
    @staticmethod
    def FromRGB(r, g, b):
        """API: Creates colour from a R,G,B values
        
        @param r:  Red value of created colour
        @param g:  Green value of created colour
        @param b:  Blue value of created colour """
        return DingoColour(wx.Color(r, g, b))

    @wxThreadSwitch
    @staticmethod
    def _setupColours():
        """Setup a list of colours we can create by name.
        
        This initialises a selection of possible sensor colours to use, allowing us to call commonly used colours by a 
        identifier instead of creating and testing each from scratch.
        """
        DingoColour.Aquamarine = DingoColour.FromName('Aquamarine')
        DingoColour.Black = DingoColour.FromName('Black')
        DingoColour.Blue = DingoColour.FromName('Blue')
        DingoColour.BlueViolet = DingoColour.FromName('Blue Violet')
        DingoColour.Brown = DingoColour.FromName('Brown')
        DingoColour.CadetBlue = DingoColour.FromName('Cadet Blue')
        DingoColour.Coral = DingoColour.FromName('Coral')
        DingoColour.CornflowerBlue = DingoColour.FromName('Cornflower Blue')
        DingoColour.Cyan = DingoColour.FromName('Cyan')
        DingoColour.DarkGrey = DingoColour.FromName('Dark Grey')
        DingoColour.DarkGreen = DingoColour.FromName('Dark Green')
        DingoColour.DarkOliveGreen = DingoColour.FromName('Dark Olive Green')
        DingoColour.DarkOrchid = DingoColour.FromName('Dark Orchid')
        DingoColour.DarkSlateBlue = DingoColour.FromName('Dark Slate Blue')
        DingoColour.DarkSlateGrey = DingoColour.FromName('Dark Slate Grey')
        DingoColour.DarkTurquoise = DingoColour.FromName('Dark Turquoise')
        DingoColour.DimGrey = DingoColour.FromName('Dim Grey')
        DingoColour.Firebrick = DingoColour.FromName('Firebrick')
        DingoColour.ForestGreen = DingoColour.FromName('Forest Green')
        DingoColour.Gold = DingoColour.FromName('Gold')
        DingoColour.Goldenrod = DingoColour.FromName('Goldenrod')
        DingoColour.Grey = DingoColour.FromName('Grey')
        DingoColour.Green = DingoColour.FromName('Green')
        DingoColour.GreenYellow = DingoColour.FromName('Green Yellow')
        DingoColour.IndianRed = DingoColour.FromName('Indian Red')
        DingoColour.Khaki = DingoColour.FromName('Khaki')
        DingoColour.LightBlue = DingoColour.FromName('Light Blue')
        DingoColour.LightGrey = DingoColour.FromName('Light Grey')
        DingoColour.LightSteelBlue = DingoColour.FromName('Light Steel Blue')
        DingoColour.LimeGreen = DingoColour.FromName('Lime Green')
        DingoColour.Magenta = DingoColour.FromName('Magenta')
        DingoColour.Maroon = DingoColour.FromName('Maroon')
        DingoColour.MediumAquamarine = DingoColour.FromName('Medium Aquamarine')
        DingoColour.MediumBlue = DingoColour.FromName('Medium Blue')
        DingoColour.MediumForestGreen = DingoColour.FromName('Medium Forest Green')
        DingoColour.MediumGoldenrod = DingoColour.FromName('Medium Goldenrod')
        DingoColour.MediumOrchid = DingoColour.FromName('Medium Orchid')
        DingoColour.MediumSeaGreen = DingoColour.FromName('Medium Sea Green')
        DingoColour.MediumSlateBlue = DingoColour.FromName('Medium Slate Blue')
        DingoColour.MediumSpringGreen = DingoColour.FromName('Medium Spring Green')
        DingoColour.MediumTurquoise = DingoColour.FromName('Medium Turquoise')
        DingoColour.MediumVioletRed = DingoColour.FromName('Medium Violet Red')
        DingoColour.MidnightBlue = DingoColour.FromName('Midnight Blue')
        DingoColour.Navy = DingoColour.FromName('Navy')
        DingoColour.Orange = DingoColour.FromName('Orange')
        DingoColour.OrangeRed = DingoColour.FromName('Orange Red')
        DingoColour.Orchid = DingoColour.FromName('Orchid')
        DingoColour.PaleGreen = DingoColour.FromName('Pale Green')
        DingoColour.Pink = DingoColour.FromName('Pink')
        DingoColour.Plum = DingoColour.FromName('Plum')
        DingoColour.Purple = DingoColour.FromName('Purple')
        DingoColour.Red = DingoColour.FromName('Red')
        DingoColour.Salmon = DingoColour.FromName('Salmon')
        DingoColour.SeaGreen = DingoColour.FromName('Sea Green')
        DingoColour.Sienna = DingoColour.FromName('Sienna')
        DingoColour.SkyBlue = DingoColour.FromName('Sky Blue')
        DingoColour.SlateBlue = DingoColour.FromName('Slate Blue')
        DingoColour.SpringGreen = DingoColour.FromName('Spring Green')
        DingoColour.SteelBlue = DingoColour.FromName('Steel Blue')
        DingoColour.Tan = DingoColour.FromName('Tan')
        DingoColour.Thistle = DingoColour.FromName('Thistle')
        DingoColour.Turquoise = DingoColour.FromName('Turquoise')
        DingoColour.Violet = DingoColour.FromName('Violet')
        DingoColour.VioletRed = DingoColour.FromName('Violet Red')
        DingoColour.Wheat = DingoColour.FromName('Wheat')
        DingoColour.White = DingoColour.FromName('White')
        DingoColour.Yellow = DingoColour.FromName('Yellow')
        DingoColour.YellowGreen = DingoColour.FromName('Yellow Green')
DingoColor = DingoColour
